//
//  ViewController.m
//  UI_10_ CustomTableViewCell
//
//  Created by li cheng on 16/7/27.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "ViewController.h"
#import "CustomTableViewCell.h"
#import "NewsObject.h"
#import "Cell.h"

@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) NSMutableArray *nameArray;
@property (nonatomic, strong) UITableView *nameTableView;
@property (nonatomic, strong) Cell *newsCell;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    // 1.数据的传递依赖Model, 传对象存对象去对象
    NewsObject *newsObject = [[NewsObject alloc] initWithNewsImage:@"1.png" newsTitle:@"dfasdfa" newsDescription:@"fdsaf" newsNumberCount:@"好的时候多少"];
    self.nameArray = [NSMutableArray arrayWithObjects:newsObject, newsObject, newsObject, nil];
//    self.nameArray = [NSMutableArray arrayWithArray:@[@"唐益梦", @"张合尉", @"高雅馨", @"符淋淋", @"孙遥", @"李毅然", @"于瀚", @"沙长健", @"卢思彤", @"徐昊", @"曹冠雄", @"陈丹明", @"罗浩", @"肖扬", @"王道林", @"宫雪", @"李成", @"冀永金", @"姜浩", @"罗鹏飞", @"李昊林", @"郭宝", @"马峰", @"刘坦奇", @"殷明静", @"邓凯", @"徐康", @"王鍠", @"韩旭", @"杨睿", @"张信宝", @"姜程程", @"包铭礼", @"杜江", @"苗钧豪"]];
    self.nameTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    [self.view addSubview:self.nameTableView];
    self.nameTableView.delegate = self;
    self.nameTableView.dataSource = self;
    [self.nameTableView registerClass:[CustomTableViewCell class] forCellReuseIdentifier:@"pool"];
    // 编辑
    self.navigationItem.rightBarButtonItem = self.editButtonItem;
    // 使用自定义cell需要修改
    // 1.注册对应cell的类型
    // 2.重用池取出cell的类型
    // 3.自定义cell继承于UITableViewCell
    
    // 多种cell混合使用
    [self.nameTableView registerClass:[Cell class] forCellReuseIdentifier:@"Cell"];
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated{
    [super setEditing:editing animated:animated];
    [self.nameTableView setEditing:editing animated:animated];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 200;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _nameArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    // 多种cell,可以根据下标确定样式
    // 注意: 判断情况一定要判断完整
    if (indexPath.row == 1) {
        CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pool" forIndexPath:indexPath];
        cell.newsObject = self.nameArray[indexPath.row];
        return cell;
    } else {
        Cell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
        return cell;
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
